package com.ruoyi.yrk.system.controller;
<<<<<<< HEAD:xc/xc-yrk/src/main/java/com/ruoyi/yrk/system/controller/ScriptEpisodeController.java
=======

>>>>>>> 49dc978e45d24fe85f98d4de0c1313c812f25ad4:xingchen/xingchen-yrk/src/main/java/com/ruoyi/yrk/system/controller/YrkScriptEpisodeController.java
import java.io.File;
import java.util.ArrayList;
import java.util.List;

<<<<<<< HEAD:xc/xc-yrk/src/main/java/com/ruoyi/yrk/system/controller/ScriptEpisodeController.java
import com.alibaba.fastjson.JSONObject;
import com.xc.common.utils.FilezUtils;
import com.xc.common.utils.WordUtils;
=======
import com.ruoyi.yrk.system.domain.YrkScriptEpisodeSceneLocale;
import com.ruoyi.yrk.system.dto.YrkScriptEpisodeImportDocDto;
import com.ruoyi.yrk.system.service.IYrkScriptEpisodeSceneLocaleService;
import com.xingchen.common.utils.StrUtils;
import com.ruoyi.yrk.system.dto.YrkScriptEpisodePathSceneDto;
import com.ruoyi.yrk.system.service.IYrkScriptEpisodePathService;
import com.xingchen.common.utils.FilezUtils;
import com.xingchen.common.utils.WordUtils;
>>>>>>> 49dc978e45d24fe85f98d4de0c1313c812f25ad4:xingchen/xingchen-yrk/src/main/java/com/ruoyi/yrk/system/controller/YrkScriptEpisodeController.java
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import java.io.IOException;
<<<<<<< HEAD:xc/xc-yrk/src/main/java/com/ruoyi/yrk/system/controller/ScriptEpisodeController.java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
=======
>>>>>>> 49dc978e45d24fe85f98d4de0c1313c812f25ad4:xingchen/xingchen-yrk/src/main/java/com/ruoyi/yrk/system/controller/YrkScriptEpisodeController.java

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
<<<<<<< HEAD:xc/xc-yrk/src/main/java/com/ruoyi/yrk/system/controller/ScriptEpisodeController.java
import com.ruoyi.yrk.system.domain.ScriptEpisode;
import com.ruoyi.yrk.system.dto.ScriptEpisodeDto;
import com.ruoyi.yrk.system.service.IScriptEpisodeService;
=======

import com.ruoyi.yrk.system.domain.YrkScriptEpisode;
import com.ruoyi.yrk.system.dto.YrkScriptEpisodeDto;
import com.ruoyi.yrk.system.service.IYrkScriptEpisodeService;
>>>>>>> 49dc978e45d24fe85f98d4de0c1313c812f25ad4:xingchen/xingchen-yrk/src/main/java/com/ruoyi/yrk/system/controller/YrkScriptEpisodeController.java
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;


/**
 * 分集剧情Controller
 *
 * @author yichen
 * @date 2021-11-21
 */
@RestController
@RequestMapping("/yrk/scriptEpisode")
<<<<<<< HEAD:xc/xc-yrk/src/main/java/com/ruoyi/yrk/system/controller/ScriptEpisodeController.java
public class ScriptEpisodeController extends BaseController
{
    @Autowired
    private IScriptEpisodeService yrkScriptEpisodeService;

/**
 * 查询分集剧情列表
 */
@PreAuthorize("@ss.hasPermi('yrk:scriptEpisode:list')")
@GetMapping("/list")
        public TableDataInfo list(ScriptEpisodeDto yrkScriptEpisode)
    {
=======
public class YrkScriptEpisodeController extends BaseController {
    @Autowired
    private IYrkScriptEpisodeService yrkScriptEpisodeService;
    @Autowired
    private IYrkScriptEpisodeSceneLocaleService scriptEpisodeSceneLocaleService;
    @Autowired
    private IYrkScriptEpisodePathService yrkScriptEpisodePathService;

    /**
     * 查询分集剧情列表
     */
    @PreAuthorize("@ss.hasPermi('yrk:scriptEpisode:list')")
    @GetMapping("/list")
    public TableDataInfo list(YrkScriptEpisodeDto yrkScriptEpisode) {
>>>>>>> 49dc978e45d24fe85f98d4de0c1313c812f25ad4:xingchen/xingchen-yrk/src/main/java/com/ruoyi/yrk/system/controller/YrkScriptEpisodeController.java
        startPage();
        List<ScriptEpisode> list = yrkScriptEpisodeService.selectdList(yrkScriptEpisode);
        return getDataTable(list);
    }

    /**
     * 导出分集剧情列表
     */
    @PreAuthorize("@ss.hasPermi('yrk:scriptEpisode:export')")
    @Log(title = "分集剧情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
<<<<<<< HEAD:xc/xc-yrk/src/main/java/com/ruoyi/yrk/system/controller/ScriptEpisodeController.java
    public void export(HttpServletResponse response, ScriptEpisodeDto yrkScriptEpisode) throws IOException
    {
=======
    public void export(HttpServletResponse response, YrkScriptEpisodeDto yrkScriptEpisode) throws IOException {

>>>>>>> 49dc978e45d24fe85f98d4de0c1313c812f25ad4:xingchen/xingchen-yrk/src/main/java/com/ruoyi/yrk/system/controller/YrkScriptEpisodeController.java
        startPage();
        List<ScriptEpisode> list = yrkScriptEpisodeService.selectdList(yrkScriptEpisode);
        ExcelUtil<ScriptEpisode> util = new ExcelUtil<ScriptEpisode>(ScriptEpisode.class);
        util.exportExcel(response, list, "分集剧情数据");
    }

    /**
     * 导入分集单集剧情
     */

    @PreAuthorize("@ss.hasPermi('yrk:scriptEpisode:importDoc')")
//    @Log(title = "doc文档转文字导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importDoc")
    public AjaxResult importDoc(YrkScriptEpisodeImportDocDto episodeImportDocDto    ) {
        if (episodeImportDocDto.getScriptId() == null) {
            return AjaxResult.error("请选择剧本");
        }
        YrkScriptEpisodeSceneLocale scriptEpisodeSceneLocale = scriptEpisodeSceneLocaleService.getById(episodeImportDocDto.getScriptId());
        if (scriptEpisodeSceneLocale == null) {
            return AjaxResult.error("请先创建剧本属性");
        }
        YrkScriptEpisode post = new YrkScriptEpisode();
        String str = "";
        File filez = null;
        try {
            // 获取文件名
            filez = FilezUtils.transferToFile(episodeImportDocDto.getFile());
            str = WordUtils.toString(filez);
            str = StrUtils.toEnglish(str, false);
//            List<String> attributes =new ArrayList<>();
//            attributes.add("角色");
//            attributes.add("道具");
            List<YrkScriptEpisodePathSceneDto> list = yrkScriptEpisodePathService.pathSceneInfo(str, episodeImportDocDto.getAttributes());
            return AjaxResult.success(list);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return AjaxResult.error("文件解析失败");
    }

    /**
<<<<<<< HEAD:xc/xc-yrk/src/main/java/com/ruoyi/yrk/system/controller/ScriptEpisodeController.java
     * 导入文档转文字
     */
//    @PreAuthorize("@ss.hasPermi('lngx:post:importDoc')")
//    @Log(title = "doc文档转文字导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importDoc")
    public AjaxResult importDoc(MultipartFile file,String paternStr) throws Exception {
        ScriptEpisode post =new ScriptEpisode();
        String str = "";
        boolean message = false;
        File filez = null;
        try {
            // 获取文件名
            filez= FilezUtils.transferToFile(file);
            str= WordUtils.toString(filez);
            paternStr =paternStr==null? "(第?=第次)":paternStr;

            Pattern pattern = Pattern.compile(paternStr,Pattern.COMMENTS);
//            Matcher matcher= pattern.matcher(str);

//            str = "北京市(海淀区)(朝阳区)";
//            paternStr = "第?=第次";
           pattern = Pattern.compile(paternStr);
            Matcher matcher = pattern.matcher(str);
            int count = 0;
            List<String> ls= new ArrayList<>();
            while (matcher.find()) {
                count = count + 1;
                if(matcher.group().length()>3  && matcher.group().length()<10){
                    ls.add(matcher.group());
                }
                System.out.println(matcher.group(0));
                System.out.println(matcher.group(1));
                System.out.println(matcher.groupCount());
                System.out.println(matcher.group());
            }
            System.out.println("共有 " + count + "个 ");
            System.out.println(JSONObject.toJSONString(ls));
            return AjaxResult.success(str);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return AjaxResult.error("文件解析失败");
    }
    /**
     * 导入分集剧情
=======
     * 导入分集剧情列表
>>>>>>> 49dc978e45d24fe85f98d4de0c1313c812f25ad4:xingchen/xingchen-yrk/src/main/java/com/ruoyi/yrk/system/controller/YrkScriptEpisodeController.java
     */
    @PreAuthorize("@ss.hasPermi('yrk:scriptEpisode:importData')")
    @Log(title = "分集剧情导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
<<<<<<< HEAD:xc/xc-yrk/src/main/java/com/ruoyi/yrk/system/controller/ScriptEpisodeController.java
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<ScriptEpisode> util = new ExcelUtil<ScriptEpisode>( ScriptEpisode.class);
        List<ScriptEpisode> list = util.importExcel(file.getInputStream());
        boolean message=false;
        if(updateSupport){
            message =yrkScriptEpisodeService.saveOrUpdateBatch(list);
        }else {
            message =yrkScriptEpisodeService.saveBatch(list);
=======
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<YrkScriptEpisode> util = new ExcelUtil<YrkScriptEpisode>(YrkScriptEpisode.class);
        List<YrkScriptEpisode> list = util.importExcel(file.getInputStream());
        boolean message = false;
        if (updateSupport) {
            message = yrkScriptEpisodeService.saveOrUpdateBatch(list);
        } else {
            message = yrkScriptEpisodeService.saveBatch(list);
>>>>>>> 49dc978e45d24fe85f98d4de0c1313c812f25ad4:xingchen/xingchen-yrk/src/main/java/com/ruoyi/yrk/system/controller/YrkScriptEpisodeController.java
        }
        return AjaxResult.success(message);
    }

    /**
     * 获取分集剧情详细信息
     */
    @PreAuthorize("@ss.hasPermi('yrk:scriptEpisode:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(yrkScriptEpisodeService.getById(id));
    }

    /**
     * 新增分集剧情
     */
    @PreAuthorize("@ss.hasPermi('yrk:scriptEpisode:add')")
    @Log(title = "分集剧情", businessType = BusinessType.INSERT)
    @PostMapping
<<<<<<< HEAD:xc/xc-yrk/src/main/java/com/ruoyi/yrk/system/controller/ScriptEpisodeController.java
    public AjaxResult add(@RequestBody ScriptEpisode scriptEpisode)
    {
        return toAjax(yrkScriptEpisodeService.save(scriptEpisode));
=======
    public AjaxResult add(@RequestBody YrkScriptEpisode yrkScriptEpisode) {
        return toAjax(yrkScriptEpisodeService.save(yrkScriptEpisode));
>>>>>>> 49dc978e45d24fe85f98d4de0c1313c812f25ad4:xingchen/xingchen-yrk/src/main/java/com/ruoyi/yrk/system/controller/YrkScriptEpisodeController.java
    }

    /**
     * 修改分集剧情
     */
    @PreAuthorize("@ss.hasPermi('yrk:scriptEpisode:edit')")
    @Log(title = "分集剧情", businessType = BusinessType.UPDATE)
    @PutMapping
<<<<<<< HEAD:xc/xc-yrk/src/main/java/com/ruoyi/yrk/system/controller/ScriptEpisodeController.java
    public AjaxResult edit(@RequestBody ScriptEpisode scriptEpisode)
    {
        return toAjax(yrkScriptEpisodeService.updateById(scriptEpisode));
=======
    public AjaxResult edit(@RequestBody YrkScriptEpisode yrkScriptEpisode) {
        return toAjax(yrkScriptEpisodeService.updateById(yrkScriptEpisode));
>>>>>>> 49dc978e45d24fe85f98d4de0c1313c812f25ad4:xingchen/xingchen-yrk/src/main/java/com/ruoyi/yrk/system/controller/YrkScriptEpisodeController.java
    }

    /**
     * 删除分集剧情
     */
    @PreAuthorize("@ss.hasPermi('yrk:scriptEpisode:remove')")
    @Log(title = "分集剧情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(yrkScriptEpisodeService.removeByIds(ids));
    }
}
